package com.zyf.mapreduce.writableCompartable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author Malegod_xiaofei
 * @create 2024-07-21-20:06
 */
public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    private FlowBean outk = new FlowBean();
    private Text outv = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        // 1 获取一行
        String line = value.toString();

        // 2 切割
        String[] split = line.split("\t");

        // 3 封装
        outv.set(split[0]);
        outk.setUpFlow(Long.parseLong(split[1]));
        outk.setDownFlow(Long.parseLong(split[2]));
        outk.setSumFlow();

        // 4 写出
        context.write(outk, outv);
    }
}